package dome1;

import org.jcp.xml.dsig.internal.dom.ApacheOctetStreamData;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-29
 * Time: 17:37
 */
public class Geme {
    private static final String[] suits = {"♥","♣","♦","♠"};

    public List<Poker> buyPoker() {
        List<Poker> pokers = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(suits[i],j);
                pokers.add(poker);
            }
        }
        return pokers;
    }

    public void shuffle(List<Poker> pokers) {
        Random random = new Random();
        for (int i = pokers.size()-1; i >0; i--) {
            int index = random.nextInt(i);
            swap(pokers,index,i);
        }
    }
    private void swap(List<Poker> pokers,int i,int j) {
        Poker tmp = pokers.get(j);
        pokers.set(j,pokers.get(i));
        pokers.set(i,tmp);
    }

    public void dealcards(List<Poker> pokers) {
        List<List<Poker>> hands = new ArrayList<>();
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        //一个人5张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Poker poker = pokers.remove(0);
                hands.get(j).add(poker);
            }
        }
        for (int i = 0; i < hands.size(); i++) {
            System.out.println("第"+(i+1)+"个人的牌:" + hands.get(i));
        }
    }
}
